def prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def nex(n):
    while True:
        n += 1
        if prime(n):
            return n

def main(words):
    n2w = {"zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}
    try:
        n2s = ''.join(n2w[word] for word in words.split())
        if len(n2s) == 3:
            n = int(n2s)
            close = n if prime(n) else nex(n)
            while True:
                prev = n - 1
                if prev > 1 and prime(prev):
                    print(prev)
                    break
                if prime(close):
                    print(close)
                    break
                close += 1
                n -= 1
        else:
            print("Wrong input")
    except KeyError:
        print("Wrong input")


main(input())
